<!-- 特殊业务标识弹窗 -->
<template>
    <Modal :value="value" @input="handleInput" width="746" class="col-2" :closable="false">
        <div slot="header">
            特殊业务标识
            <Icon class="f-fr" type="ios-close" @click="closeModel"/>
        </div>
        <CheckboxGroup v-model="selectedList">
            <Checkbox
                v-for="(item, index) in list"
                :disabled="editORshow"
                :key="index"
                :label="item.label"
            >
            </Checkbox>
        </CheckboxGroup>
        <div slot="footer">
            <Button style="display:none" type="default" @click="closeModel">取消</Button>
            <Button type="primary" @click="saveSpecialIden">确定</Button>
        </div>
    </Modal>
</template>

<script>
export default {
    name: 'SpecialIdenModal',
    props: {
        value: {
            default: false,
            type: Boolean
        },
        specialIden: {
            default: function () {
                return {
                    tempList: [],
                    editORshow: false
                }
            },
            type: Object
        }
    },
    data () {
        return {
            specialIdenModal: false,
            editORshow: null,
            list: [
                { code: 0, label: '国际赛事' },
                { code: 0, label: '特殊进出军工物资' },
                { code: 0, label: '国际援助物资' },
                { code: 0, label: '国际会议' },
                { code: 0, label: '直通放行' },
                { code: 0, label: '外交礼遇' },
                { code: 0, label: '转关' }
            ],
            selectedList: []
        }
    },
    created () {
        this.selectedList = this.specialIden.tempList
        this.editORshow = this.specialIden.editORshow
    },
    methods: {
        closeModel () {
            this.handleInput(false)
        },
        handleInput (v) {
            this.$emit('input', v)
        },
        saveSpecialIden () {
            let labelString = this.selectedList.toString()
            let codeList = []
            this.list.forEach(item => {
                if (labelString.indexOf(item.label) !== -1) {
                    item.code = 1
                } else {
                    item.code = 0
                }
                codeList.push(item.code)
            })

            let res = {
                labelString: labelString,
                codeString: codeList.join('')
            }
            this.$emit('saveSpecialIden', res)
            this.closeModel()
        }
    }
}
</script>
